﻿using System;
using Ewk.Runtime.Serialization.PositionBased;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Runtime.Serialization.UnitTests.PositionBased
{
    [TestClass]
    public class PositionBasedDatafieldAttributeTests
    {
        [TestMethod]
        public void PositionBasedDatafield_is_an_Attribute()
        {
            var attribute = NewInstance();
            Assert.IsInstanceOfType(attribute, typeof(Attribute));
        }

        [TestMethod, ExpectedException(typeof(ArgumentException))]
        public void PositionBasedDatafield_cannot_be_initialized_with_a_negative_start_parameter()
        {
            new PositionBasedDatafieldAttribute(-1, 1);
        }

        [TestMethod, ExpectedException(typeof(ArgumentException))]
        public void PositionBasedDatafield_cannot_be_initialized_with_a_negative_length_parameter()
        {
            new PositionBasedDatafieldAttribute(0, -1);
        }

        [TestMethod, ExpectedException(typeof(ArgumentException))]
        public void PositionBasedDatafield_cannot_be_initialized_with_a_zero_length_parameter()
        {
            new PositionBasedDatafieldAttribute(0, 0);
        }

        private static PositionBasedDatafieldAttribute NewInstance()
        {
            return new PositionBasedDatafieldAttribute(0, 1);
        }
    }
}
